package com.nondo.rdp.finance.repository.activity;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.finance.domain.activity.MarketCourse;

public interface MarketCourseRepository extends JpaRepository<MarketCourse, Long>, JpaSpecificationExecutor<MarketCourse> {
    @Query("select a from MarketCourse a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<MarketCourse> findOne(@Param("id") int id);

    @Modifying
    @Query("update MarketCourse set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    MarketCourse save(MarketCourse marketCourse);

    @Query("select a from MarketCourse a where a.user.id=? and type=? and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
	MarketCourse getOne(Long uid, int type);

    @Query("select count(a.id) from MarketCourse a where a.course.id=? and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
	int getOneByCid(Long cid);

}
